package org.amse.ys.sndeditor.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import org.amse.ys.sndeditor.model.IEditor;
import android.view.MotionEvent;
import android.view.View;

public class MyView extends View {
	private IEditor myEditor;

	public MyView(Context c, IEditor editor) {
		super(c);
		myEditor = editor;

	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		myEditor.setSize(w, h);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		Bitmap b = (Bitmap) myEditor.getDrawer().getDrawable();
		canvas.drawBitmap(b, 0, 0, null);
	}

	@Override
	public void refreshDrawableState() {
		if (myEditor.isScreenChanged()) {
			invalidate();
		}
		super.refreshDrawableState();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		myEditor.onTouch((int) event.getRawX(), (int) event.getRawY(), event
				.getDownTime());
		refreshDrawableState();
		return true;
	}

}